package com.kyist.frp.config;

import com.kyist.frp.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 登录过滤配置
 *
 * @Author kyist
 * @Date 2021/12/15 21:37
 */
@Configuration
public class LoginConfig implements WebMvcConfigurer {


    /**
     * 注册拦截器
     * @param registry registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加
        InterceptorRegistration registration = registry.addInterceptor(new LoginInterceptor());
        //设置拦截路径
        registration.addPathPatterns("/**");                      //所有路径都被拦截
        registration.excludePathPatterns(                         //添加不拦截路径
                "/handler",
                "/login/*",            //登录
                "/login.html",           //html静态资源
                "/**/*.js",              //js静态资源
                "/**/*.css",             //css静态资源
                "/**/*.woff",
                "/**/*.ttf"
        );
    }


//    // 配置视图跳转
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/").setViewName("login");
//        registry.addViewController("/login.html").setViewName("login");
//        registry.addViewController("/frpcInfo.html").setViewName("frpcInfo");
//    }

}
